package com.example.community.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.community.dao.mapper.DiscussPostMapper;
import com.example.community.dao.pojo.DiscussPost;
import com.example.community.service.DiscussPostService;
import com.example.community.uitls.CommunityUtil;
import com.example.community.uitls.SensitiveFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DiscussPostServiceImpl implements DiscussPostService {

    @Autowired
    private DiscussPostMapper discussPostMapper;

    @Autowired
    private SensitiveFilter sensitiveFilter;

    public List<DiscussPost> findDiscussPosts(int userId, int offset, int limit) {
        return discussPostMapper.selectDiscussPosts(userId, offset, limit);
    }

    public int findDiscussPostRows(int userId) {
        return discussPostMapper.selectDiscussPostRows(userId);
    }

    @Override
    public void insertDiscussPost(DiscussPost discussPost) {
        discussPost.setContent(sensitiveFilter.filter(discussPost.getContent()));
        discussPost.setTitle(sensitiveFilter.filter(discussPost.getTitle()));
        discussPostMapper.insertDiscussPost(discussPost);
    }

    @Override
    public DiscussPost findDiscussPostById(int DiscussPostId) {
        return discussPostMapper.selectById(DiscussPostId);
    }

    @Override
    public int updateCommentCount(int id, int commentCount) {
        return discussPostMapper.updateCommentCount(id,commentCount);
    }

    //0-普通; 1-置顶;
    @Override
    public int updateType(int postId, int type) {

        return 0;
    }

    //0-正常; 1-精华; 2-拉黑;
    @Override
    public int updateStatus(int postId, int status) {
        return 0;
    }


    @Override
    public List<DiscussPost> selectDiscussPosts(int userId, int offset, int limit) {
        return discussPostMapper.selectDiscussPosts(userId,offset,limit);
    }

    @Override
    public Page<DiscussPost> getDiscussPostsPage(Integer page) {
        Page<DiscussPost> page1 = new Page<>(page,5);
        return discussPostMapper.selectPage(page1,new LambdaQueryWrapper<>());
    }
}
